/*
 * @Description: 算术运算符、比较运算符
 * @Author: zzj
 * @Date: 2021-08-31 10:57:47
 * @LastEditors: zzj
 * @LastEditTime: 2021-08-31 12:00:46
 */

// 通常情况下，对于+、-、*、%、/的运算需要是Number类型的值
var n1 = 1;
var n2 = 2;
var n3 = 10;
console.log(n1+n2);
console.log(n3/n2);
console.log(n3%n2);
//如果出现不是Number类型的情况 +
//在js中+除了可以做运算外，还可以做拼接的操作
var s1 = "hello";
var s2 = "zzj";
var str = s1 +s2;//这是+做拼接的操作
console.log(str);
//如果两边不为string和object时，做运算
/*var bool = true;
console.log(n1+bool);*/
/*var bool = null;
console.log(n1+bool);*/
var bool = undefined;
console.log(n1+bool);
//如果两边有一边为string类型时，会将另一个变量转为string，做拼接
console.log(s1+n1);
console.log(s1+bool);
//比较操作符==、!=、===、!==
//==只比较值, ===既比较值也比较类型
var num1 = 1;
var num2 = "1";
var num3 = 2;
console.log(num1 == num2);
console.log(num1 != num2);
console.log(num1 === num2);
console.log(num1 !== num2);
// >、>=、<、<=
console.log(num1>num3);
console.log(num1>=num3);
console.log(num1<num3);
console.log(num1<=num3);
var res = num1+1 >= num3;
console.log(res);
//比较2个对象是否相等
var str1 = "xiaoming";
var str2 = "xiaoming";
console.log(str1===str2);
var obj1 = {
    name:"xiaoming"
}
var obj2 = {
    name:"xiaoming"
}
console.log(obj1===obj2);
//确实想要判断两个相同内容的对象，怎么办？
var obj1_str = JSON.stringify(obj1); //序列化：将对象转为JSON字符串
var obj2_str = JSON.stringify(obj2);
console.log(obj1_str)
//JSON.parse() //反序列化：将JSON字符串转为对象
console.log(obj1_str===obj2_str);
var obj3 = JSON.parse(JSON.stringify(obj1));  //深拷贝